home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / fpc / source / docs / objectex / ex20.pp < prev    next >
Encoding:
Text File  |  2000-01-01  |  661 b   |  27 lines

  1. Program ex20;
  2.  
  3. { Program to demonstrate the TMemoryStream.Truncate method }
  4.  
  5. Uses Objects;
  6.  
  7. Var L : String;
  8.     P : PString;
  9.     S : PMemoryStream; 
  10.     I,InitMem : Longint;
  11.        
  12. begin
  13.   initMem:=Memavail;
  14.   L:='Some constant string';
  15.   { Buffer size of 100 }
  16.   S:=New(PMemoryStream,Init(1000,100));
  17.   Writeln ('Free memory : ',Memavail);
  18.   Writeln ('Writing 100 times "',L,'" to stream.');
  19.   For I:=1 to 100 do 
  20.     S^.WriteStr(@L);
  21.   Writeln ('Finished. Free memory : ',Memavail);
  22.   S^.Seek(100);
  23.   S^.Truncate;
  24.   Writeln ('Truncated at byte 100. Free memory : ',Memavail);
  25.   Dispose (S,Done);
  26.   Writeln ('Finished. Lost ',InitMem-Memavail,' Bytes.');
  27. end.